package logic

import (
	"context"
	"gorm.io/gorm"
	"user-goods/models/mysql"

	"user-goods/userrpc/internal/svc"
	"user-goods/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodListLogic {
	return &GoodListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodListLogic) GoodList(in *userrpc.GoodListRequest) (*userrpc.GoodListResponse, error) {
	// todo: add your logic here and delete this line

	list := mysql.Goods{
		Model: gorm.Model{ID: uint(in.GoodId)},
	}
	mysql.DB.Debug().Find(&list)

	return &userrpc.GoodListResponse{
		GoodName: list.GoodName,
		Price:    float32(list.Price),
		Num:      list.Num,
		UserId:   list.UserId,
	}, nil
}
